package com.zdj.presentation.app;

import android.content.Intent;
import android.os.Handler;

import com.lkskt.frame.jni.Liblksjni;
import com.zdj.data.entity.LoginInfoDao;
import com.zdj.data.events.LoginEvent;
import com.zdj.data.utils.DBUtil;
import com.zdj.presentation.R;
import com.zdj.presentation.base.BaseActivity;
import com.zdj.presentation.base.BaseApplication;
import com.zdj.presentation.modules.demo.TestGsonActivity;
import com.zdj.presentation.modules.user.views.UserDetailActivity;
import com.zdj.presentation.modules.main.views.HomeActivity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class SplashActivity extends BaseActivity {

    private Handler handler = new Handler();

    private Runnable runnable = ()->{
        startUdpService();
    };

    private void startUdpService() {
        Intent intent = new Intent(this, UdpService.class);
        intent.putExtra("cmd", Liblksjni.SS_LOGIN);
        startService(intent);
    }

    @Override
    protected void initVms() {

    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void setViewModel2Binding() {

    }

    @Override
    protected void initView() {
//        handler.postDelayed(runnable,2000);
        toActivity(TestGsonActivity.class);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
    }

    /**
     * 登录成功的回调 <br/>
     * 作者 ：dengjie zhang <br/>
     * created at 2017/1/23 10:09
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void loginCallback(LoginEvent event){
        // 存储数据
        BaseApplication.sLoginInfo = event.mLoginInfo;
        LoginInfoDao loginInfoDao = DBUtil.daoSession.getLoginInfoDao();
        loginInfoDao.insertOrReplace(event.mLoginInfo);
        toActivity(HomeActivity.class);
        finish();
    }
}
